package com.freemalll.merchant.mapper;

import com.freemalll.merchant.domain.vo.merchantReport.MerchantBizPerfMonthVo;
import com.freemalll.merchant.domain.vo.merchantReport.MerchantBizPerfVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MerchantBusinessMapper {

    /**
     * 放款日统计
     *
     * @param merId
     * @return
     */
    @Select(" SELECT m.biz_id," +
            " m.month_id,m.apply_cnt,m.pass_ratio,m.loan_cnt,m.loan_amt,m.over_cnt_loan as over_cnt,m.over_balance_amt_loan as over_balance_amt," +
            " m.fpd_over_cnt_loan  as fpd_over_cnt, m.over_amt_ratio_loan as over_amt_ratio, m.fpd_over_amt_ratio_loan  as fpd_over_amt_ratio, " +
            " m.new_over_amt_ratio_loan as new_over_amt_ratio," +
            " SUBSTRING_INDEX(m.month_id, '-', 1) as yearId " +
            " FROM ads_mcht_biz_perf_m m" +
            " WHERE m.biz_id = #{merId} " +
            " ORDER BY m.month_id ASC")
    List<MerchantBizPerfMonthVo> getBusinessPerformanceMonthByLoanDisbursementDate(@Param("merId") String merId);

    /**
     * 清算日统计
     *
     * @param merId
     * @return
     */
    @Select(" SELECT m.biz_id," +
            " m.month_id,m.apply_cnt,m.pass_ratio,m.loan_cnt,m.loan_amt," +
            " m.over_cnt,m.over_balance_amt,m.fpd_over_cnt," +
            " m.over_amt_ratio,m.fpd_over_amt_ratio,m.new_over_amt_ratio," +
            " SUBSTRING_INDEX(m.month_id, '-', 1) as yearId " +
            " FROM ads_mcht_biz_perf_m m" +
            " WHERE m.biz_id = #{merId} " +
            " ORDER BY m.month_id ASC")
    List<MerchantBizPerfMonthVo> getBusinessPerformanceMonthByLiquidationDate(@Param("merId") String merId);

    /**
     * 获取商户业务表现数据
     *
     * @param merId
     * @return
     */
    @Select(" SELECT * from ads_mcht_biz_perf where biz_id = #{merId}")
    MerchantBizPerfVo getBusinessPerformance(@Param("merId") String merId);
}
